<?php if ( ! defined('FCPATH')) exit('No direct script access allowed');
/**
* Gestion de la connexion sur le site
* @author Richard G
* @package Layout
*/
class Authenticate
{

	private $CI;

	/**
	* Construit l'authenticate
	*/
	public function __construct()
	{
		$this->CI =& get_instance();
	}

	/**
	*	Logout du membre
	*/
	public function logout()
	{
		@session_destroy();
		return true;
	}

	/**
	*	Authentification du membre
	*/
	public function authen()
	{
		$this->CI->config->load('my_site', true, true);
		$section_admin = $this->CI->config->item('section_admin', 'my_site');
		$data = array();
		if($this->CI->input->server('REQUEST_METHOD') == 'POST' &&
			$this->CI->input->post("panel_login", false) &&
			$this->CI->input->post("panel_pwd", false)) {
			$me = $this->CI->member->getByAuth(
								$this->CI->input->post("panel_login"),
								$this->CI->input->post("panel_pwd"));
			if($me === false) {
				$data['error_auth'] = 1;
				if($this->CI->router->directory != $section_admin) {
					$this->CI->layout->headerData($data);
				}
				@session_destroy();
			}else {
				$this->CI->user_session->set_value("member", $me);
			}
		}
		if($this->CI->user_session->get_value(array("member", "member_status")) == 1) {
			return;
		}
		if($this->CI->router->directory == $section_admin) {
			$this->CI->layout->contentLogin('layout/login', $data);
		}
	}
}